package player;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.omg.CORBA.ORB;
import org.omg.CORBA.StringHolder;

import common.CommonTools;

import player.playerService;
import player.playerServiceHelper;
import player.Player;

public class PlayerClient {

	
		private playerService playerService;

		public PlayerClient(playerService playerService) {
			this.playerService = playerService;
		}

		public void createPlayer(String firstName, String lastName, int age,
				String userName, String password, String clientIpAddress) {
			Player player = new Player(firstName, lastName, age, userName,
						password, clientIpAddress);
				
				CommonTools.writeLog("client", "client", "create player:" + player, false);
				StringHolder status = new StringHolder();
				playerService.createPlayerAccount(firstName, lastName,(short) age, userName, password, clientIpAddress, status);
			 
		}

		public void signIn(String userName, String password, String clientIpAddress) {
			String content = "player signIn started:" + "userName:" + userName +";ipAddress:"+ clientIpAddress;
				
				CommonTools.writeLog("client", "client", content, false);
				StringHolder status = new StringHolder();
				playerService.playerSignIn(userName, password, clientIpAddress,status);
				content = "player signIn succeeded:" + "userName:" + userName +";ipAddress:"+ clientIpAddress +" Status:"+status.value;				
				CommonTools.writeLog("client", "client", content, false);
			
		}

		public void signOut(String userName, String clientIpAddress) {
			
				String content = "player signOut started:" + "userName:" + userName +";ipAddress:"+ clientIpAddress;
				System.out.println(content);
				CommonTools.writeLog("client", "client", content, false);
				StringHolder status = new StringHolder();
				playerService.playerSignOut(userName, clientIpAddress, status);
				content = "player signOut succees status:"+ status.value + "userName:" + userName +";ipAddress:"+ clientIpAddress;
				CommonTools.writeLog("client", "client", content, false);
			
		}
		
		public void transferAccount(String userName,String password, String oldIpAddress, String newIpAddress) {
			
			String content = "player account transfer started:" + "userName:" + userName +";oldIpAddress:"+ oldIpAddress +";newIpAddress:"+ newIpAddress;
			CommonTools.writeLog("client", "client", content, false);
			StringHolder status = new StringHolder();
			playerService.transferAccount(userName,password,  oldIpAddress, newIpAddress, status);
			
			content = "player account transfer succees status:"+ status.value + " userName:" + userName +";oldIpAddress:"+ oldIpAddress +";newIpAddress:"+ newIpAddress;
			CommonTools.writeLog("client", "client", content, false);
		
		}
}
